package cn.iocoder.yudao.module.promotion.dal.mysql.points;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.promotion.controller.admin.points.pointsproduct.PointsProductExportReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.points.pointsproduct.PointsProductPageReqVO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.points.PointsProductDO;
import org.apache.ibatis.annotations.Mapper;

/**
 * 积分商品 Mapper
 *
 * @author 超级管理员
 */
@Mapper
public interface PointsProductMapper extends BaseMapperX<PointsProductDO> {

    default PageResult<PointsProductDO> selectPage(PointsProductPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<PointsProductDO>()
                .eqIfPresent(PointsProductDO::getActivityId, reqVO.getActivityId())
                .eqIfPresent(PointsProductDO::getSpuId, reqVO.getSpuId())
                .eqIfPresent(PointsProductDO::getSkuId, reqVO.getSkuId())
                .eqIfPresent(PointsProductDO::getActivityStatus, reqVO.getActivityStatus())
                .betweenIfPresent(PointsProductDO::getActivityStartTime, reqVO.getActivityStartTime())
                .betweenIfPresent(PointsProductDO::getActivityEndTime, reqVO.getActivityEndTime())
                .eqIfPresent(PointsProductDO::getCombinationPrice, reqVO.getCombinationPrice())
                .eqIfPresent(PointsProductDO::getPoints, reqVO.getPoints())
                .betweenIfPresent(PointsProductDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(PointsProductDO::getId));
    }

    default List<PointsProductDO> selectList(PointsProductExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<PointsProductDO>()
                .eqIfPresent(PointsProductDO::getActivityId, reqVO.getActivityId())
                .eqIfPresent(PointsProductDO::getSpuId, reqVO.getSpuId())
                .eqIfPresent(PointsProductDO::getSkuId, reqVO.getSkuId())
                .eqIfPresent(PointsProductDO::getActivityStatus, reqVO.getActivityStatus())
                .betweenIfPresent(PointsProductDO::getActivityStartTime, reqVO.getActivityStartTime())
                .betweenIfPresent(PointsProductDO::getActivityEndTime, reqVO.getActivityEndTime())
                .eqIfPresent(PointsProductDO::getCombinationPrice, reqVO.getCombinationPrice())
                .eqIfPresent(PointsProductDO::getPoints, reqVO.getPoints())
                .betweenIfPresent(PointsProductDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(PointsProductDO::getId));
    }

    default List<PointsProductDO> selectListByActivityIds(Collection<Long> ids) {
        return selectList(PointsProductDO::getActivityId, ids);
    }

    default List<PointsProductDO> selectList(PointsProductPageReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<PointsProductDO>()
                .eqIfPresent(PointsProductDO::getActivityId, reqVO.getActivityId())
                .eqIfPresent(PointsProductDO::getSpuId, reqVO.getSpuId())
                .eqIfPresent(PointsProductDO::getSkuId, reqVO.getSkuId())
                .eqIfPresent(PointsProductDO::getActivityStatus, reqVO.getActivityStatus())
                .betweenIfPresent(PointsProductDO::getActivityStartTime, reqVO.getActivityStartTime())
                .betweenIfPresent(PointsProductDO::getActivityEndTime, reqVO.getActivityEndTime())
                .eqIfPresent(PointsProductDO::getCombinationPrice, reqVO.getCombinationPrice())
                .eqIfPresent(PointsProductDO::getPoints, reqVO.getPoints())
                .betweenIfPresent(PointsProductDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(PointsProductDO::getId));
    }

    default void deleteBySpuId(Long spuId) {
        delete(new LambdaQueryWrapperX<PointsProductDO>()
                .eq(PointsProductDO::getSpuId, spuId));
    }
}
